home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Archives / Timing / DaSayTime.lha / DaSayTime / DaSayTime.e < prev    next >
Encoding:
Text File  |  1995-09-13  |  9.0 KB  |  433 lines

  1. OPT OSVERSION=37
  2.  
  3. /*********************************************************************
  4. *
  5. * $VER: Kode:AmigaE/E-Kode/__FASE_2___/DaSayTime/DaSayTime.e 0.4 (12.09.95) $
  6. *
  7. * $RCSfile: DaSayTime.e $
  8. * $Revision: 1.6 $
  9. * $Author: dapp $
  10. * $Locker: dapp $
  11. * $AmigaDATE: 12.09.95   $
  12. * $Log: DaSayTime.e $
  13. # Revision 1.6  1995/09/12  07:51:15  dapp
  14. # Program $VER bumped
  15. #
  16. # Revision 1.5  1995/09/12  07:38:59  dapp
  17. # Bug, BYTE read from $0 (vol:=Val(args[2]))
  18. #
  19. # Revision 1.4  1995/09/12  07:35:46  dapp
  20. # Bug when the clock was 00:__:__ changed too 24:__:__
  21. # Added VOLUME option
  22. # Amiga Revision bumped
  23. #
  24. # Revision 1.3  1995/09/12  07:32:50  dapp
  25. # Added CONST instead of #define
  26. # Added version string
  27. # Added _better_ error handling
  28. # Added 12H option (18:00:00->06:00:00)     (SSP)
  29. # Added SAMPLERATE option (DEFAULT 8000)
  30. # Added real arg. handling
  31. # Added PAL/NTSC check
  32. # Amiga Revision bumped
  33. #
  34. # Revision 1.2  1995/09/12  07:31:54  dapp
  35. # First try!! Works :)
  36. # Amiga Revision bumped
  37. #
  38. # Revision 1.1  1995/09/12  07:31:22  dapp
  39. # Initial revision
  40. #
  41. * TODO:
  42. *
  43. *   o Figure out why
  44. *                IF arequest.length=4 THEN DeleteIORequest(arequest) /*WORKS*/
  45. *                IF arequest             THEN DeleteIORequest(arequest) /*CRASH*/
  46. *            Data:
  47. *                ioReq = CreateIORequest( ioReplyPort, size );
  48. *                ioReq - A pointer to the new IORequest block, or NULL.
  49. *                NULL:=NIL!!!!!
  50. *
  51. * NOTES:
  52. *
  53. *   o ci -l -f <filename> ; Amiga Revision bumped
  54. *
  55. *
  56. * AUTHOR :
  57. *
  58. *   o Jørgen 'Da' Larsen (dapp@iesd.auc.dk)
  59. *      Carl Blochs Vej 20
  60. *      9000 Aalborg
  61. *      Denmark
  62. *
  63. * IDEA   :
  64. *
  65. *   o saytime - Jef Poskanzer
  66. *
  67. */
  68.  
  69.  
  70. MODULE    'devices/audio',
  71.         'dos/datetime',
  72.         'dos/dos',
  73.         'dos/rdargs',
  74.         'exec/io',
  75.         'exec/memory',
  76.         'exec/ports',
  77.         'graphics/gfxbase'
  78.  
  79.  
  80. CONST PH_ONE = 1
  81. CONST PH_TWO = 2
  82. CONST PH_THREE = 3
  83. CONST PH_FOUR = 4
  84. CONST PH_FIVE = 5
  85. CONST PH_SIX = 6
  86. CONST PH_SEVEN = 7
  87. CONST PH_EIGHT = 8
  88. CONST PH_NINE = 9
  89. CONST PH_TEN = 10
  90. CONST PH_ELEVEN = 11
  91. CONST PH_TWELVE = 12
  92. CONST PH_THIRTEEN = 13
  93. CONST PH_FOURTEEN = 14
  94. CONST PH_FIFTEEN = 15
  95. CONST PH_SIXTEEN = 16
  96. CONST PH_SEVENTEEN = 17
  97. CONST PH_EIGHTEEN = 18
  98. CONST PH_NINETEEN = 19
  99. CONST PH_TWENTY = 20
  100. CONST PH_THIRTY = 21
  101. CONST PH_FORTY = 22
  102. CONST PH_FIFTY = 23
  103. CONST PH_THE_TIME_IS = 24
  104. CONST PH_OCLOCK = 25
  105. CONST PH_OH = 26
  106. CONST PH_EXACTLY = 27
  107. CONST PH_AND = 28
  108. CONST PH_SECOND = 29
  109. CONST PH_SECONDS = 30
  110.  
  111. CONST BUFFSIZE = 8192
  112.  
  113. ENUM ERR_ARG=1, ERR_VOL, ERR_INT, ERR_OPEN, ERR_MEM, ERR_PORT, ERR_IO
  114.  
  115. DEF path:PTR TO LONG, rate=8000, vol
  116.  
  117. PROC main() HANDLE
  118.  /* ReadArgs DEF's */
  119.  DEF readargs:PTR TO rdargs, args:PTR TO LONG
  120.  DEF eng
  121.  
  122.  /* Time DEF's */
  123.  DEF dt:datetime,ds:PTR TO datestamp
  124.  DEF hour,min,sec
  125.  
  126.  IF (readargs:=ReadArgs('P=PATH/A,S=SAMPLERATE,V=VOLUME,H=12H/S',args:=[NIL,NIL,NIL,NIL],NIL))=NIL THEN Throw(ERR_ARG,0)
  127.  
  128.  /* Arg Handling */
  129.  path:=String(StrLen(args[0]))
  130.  StrCopy(path,args[0],ALL)
  131.  
  132.  IF args[1]<>NIL        
  133.     rate:=Val(args[1])
  134.  ELSE
  135.     rate:=8000
  136.  ENDIF
  137.  
  138.  IF args[2] THEN vol:=Val(args[2])
  139.  IF vol<>NIL
  140.      IF ( (vol<1) OR (vol>64) )
  141.         Throw(ERR_VOL,0)
  142.     ENDIF
  143.  ELSE
  144.     vol:=64
  145.  ENDIF
  146.  
  147.  eng:=args[3]
  148.  
  149.  /* Get the current time */
  150.  ds:=DateStamp(dt.stamp)
  151.  min,hour:=Mod(ds.minute,60)
  152.  sec:=ds.tick/50
  153.  
  154.  /* Say the time is */
  155.  sayphrase( PH_THE_TIME_IS );
  156.  
  157.  /* Say Hour */
  158.  IF eng=TRUE
  159.     IF ( hour=0 )
  160.         saynumber( 12, 0 )
  161.     ELSEIF ( hour > 12 )
  162.         saynumber( hour - 12, 0 )
  163.     ELSE
  164.         saynumber( hour, 0 )
  165.      ENDIF
  166.  ELSE
  167.     IF ( hour=0 )
  168.         saynumber( 24, 0 )
  169.     ELSE
  170.         saynumber( hour, 0 )
  171.     ENDIF
  172.  ENDIF
  173.  
  174.  /* Say min. */
  175.  IF ( min = 0 )
  176.     sayphrase ( PH_OCLOCK )
  177.  ELSE
  178.     saynumber( min, 1 )
  179.  ENDIF
  180.  
  181.  /* Say sec. */
  182.  IF ( sec = 0 )
  183.     sayphrase( PH_EXACTLY )
  184.  ELSE
  185.     sayphrase( PH_AND )
  186.     saynumber( sec, 0 )
  187.     IF ( sec = 1 )
  188.         sayphrase( PH_SECOND )
  189.     ELSE
  190.         sayphrase( PH_SECONDS )
  191.     ENDIF
  192.  ENDIF
  193.  
  194. EXCEPT
  195.     SELECT exception
  196.         CASE ERR_INT
  197.             PrintF( 'DaSayTime: Internal error - \s\n', exceptioninfo )
  198.         CASE ERR_VOL
  199.             PrintF( 'DaSayTime: Option VOLUME need a value from 1 to 64\n')
  200.         CASE ERR_ARG
  201.             PrintF('DaSayTime (c) 1995 Jørgen \aDa\a Larsen (Posse Pro. DK)\n'+
  202.                    'Syntax:  DaSayTime <P=PATH> [S=SAMPLERATE] [V=VOLUME] [H=12H]\n'+
  203.                    'Example: DaSayTime Work:music/DaSayTime/Sounds/\n')
  204.     ENDSELECT
  205. ENDPROC
  206.  
  207. PROC sayfile( filename )
  208.     DEF execstr[256]:STRING
  209.     StringF(execstr,'\s\s',path,filename)
  210.     play(execstr,rate)
  211. ENDPROC
  212.  
  213. PROC play(filename,rate) HANDLE
  214.     /* Audio DEF's */
  215.     DEF arequest:ioaudio, reply=NIL, ior:PTR TO io, adevice=1, mnode:PTR TO mn
  216.  
  217.     /* File DEF's */
  218.     DEF memoryblock=NIL, file, len
  219.  
  220.     /* NTSC/PAL check DEF's */
  221.     DEF gfxBase:PTR TO gfxbase, clock 
  222.  
  223.     /* Check if PAL or NTSC */        
  224.     gfxBase:=gfxbase
  225.     IF gfxBase.displayflags AND PAL
  226.         clock := 3546895;         /* PAL clock */
  227.     ELSE
  228.         clock := 3579545;         /* NTSC clock */
  229.     ENDIF
  230.  
  231.     IF (file:=Open(filename,MODE_OLDFILE))=NIL THEN Throw(ERR_OPEN,filename)
  232.  
  233.     IF (memoryblock:=AllocMem(BUFFSIZE,MEMF_CHIP))=NIL THEN Throw(ERR_MEM,BUFFSIZE)
  234.  
  235.     IF (reply:=CreateMsgPort())=NIL THEN Throw(ERR_PORT,0)
  236.  
  237.     IF (arequest:=CreateIORequest(reply, SIZEOF ioaudio))=NIL THEN Throw(ERR_IO,0)
  238.  
  239.     /* want to allocate and use any channel with OpenDev() */
  240.     arequest.data    := [1,2,4,8]:CHAR
  241.     arequest.length := 4                    /* This number is checks in EXECPT */
  242.     ior                := arequest
  243.     ior.command        := ADCMD_ALLOCATE
  244.  
  245.     IF (adevice:=OpenDevice('audio.device', 0, arequest, 0))<>NIL THEN Throw(ERR_OPEN,'audio.device')
  246.  
  247.     len:=Read(file,memoryblock,BUFFSIZE)
  248.     ior.flags        := ADIOF_PERVOL
  249.     ior.command        := CMD_WRITE
  250.     arequest.data    := memoryblock
  251.     arequest.length := len
  252.     arequest.volume := vol                    /* volume = MAX */
  253.     arequest.period := Div(clock,rate)        /* set frequency */
  254.     arequest.cycles := 1                    /* 1 cycle only */
  255.     mnode            := arequest
  256.     mnode.replyport := reply
  257.  
  258.     /* start audio device */
  259.     beginIO(arequest)
  260.  
  261.     /* clean up */
  262.     WaitPort(mnode.replyport)
  263.     GetMsg(mnode.replyport)
  264. EXCEPT DO
  265.     IF file THEN Close(file)
  266.     IF memoryblock THEN FreeMem(memoryblock,BUFFSIZE)
  267.     IF reply THEN DeleteMsgPort(reply)
  268.     IF arequest.length=4 THEN DeleteIORequest(arequest)
  269.     IF adevice=NIL THEN CloseDevice(arequest)
  270.     SELECT exception
  271.         CASE ERR_MEM
  272.             PrintF( 'DaSayTime: Could\an allocate \s bytes\n', exceptioninfo )
  273.         CASE ERR_PORT
  274.             PrintF( 'DaSayTime: Could\an Create Message Port\n')
  275.         CASE ERR_IO
  276.             PrintF( 'DaSayTime: Could\an Create IO port\n')
  277.         CASE ERR_OPEN
  278.             PrintF( 'DaSayTime: Could\an open \s\n', exceptioninfo )
  279.     ENDSELECT
  280. ENDPROC
  281.  
  282. PROC beginIO(arequest)
  283.     MOVE.L    arequest,A1
  284.     MOVE.L    A6,-(A7)
  285.     MOVE.L    $14(A1),A6
  286.     JSR -$1E(A6)
  287.     MOVE.L    (A7)+,A6
  288. ENDPROC
  289.  
  290. PROC saydigit( n )
  291.     SELECT n
  292.         CASE 1
  293.             sayphrase( PH_ONE )
  294.         CASE 2
  295.             sayphrase( PH_TWO )
  296.         CASE 3
  297.             sayphrase( PH_THREE )
  298.         CASE 4
  299.             sayphrase( PH_FOUR )
  300.         CASE 5
  301.             sayphrase( PH_FIVE )
  302.         CASE 6
  303.             sayphrase( PH_SIX )
  304.         CASE 7
  305.             sayphrase( PH_SEVEN )
  306.         CASE 8
  307.             sayphrase( PH_EIGHT )
  308.         CASE 9
  309.             sayphrase( PH_NINE )
  310.         DEFAULT
  311.             Throw(ERR_INT,'saydigit()')
  312.     ENDSELECT
  313. ENDPROC
  314.  
  315. PROC sayphrase( phrase )
  316.     SELECT phrase
  317.         CASE PH_ONE
  318.             sayfile( '1.iff' )
  319.         CASE PH_TWO
  320.             sayfile( '2.iff' )
  321.         CASE PH_THREE
  322.             sayfile( '3.iff' )
  323.         CASE PH_FOUR
  324.             sayfile( '4.iff' )
  325.         CASE PH_FIVE
  326.             sayfile( '5.iff' )
  327.         CASE PH_SIX
  328.             sayfile( '6.iff' )
  329.         CASE PH_SEVEN
  330.             sayfile( '7.iff' )
  331.         CASE PH_EIGHT
  332.             sayfile( '8.iff' )
  333.         CASE PH_NINE
  334.             sayfile( '9.iff' )
  335.         CASE PH_TEN
  336.             sayfile( '10.iff' )
  337.         CASE PH_ELEVEN
  338.             sayfile( '11.iff' )
  339.         CASE PH_TWELVE
  340.             sayfile( '12.iff' )
  341.         CASE PH_THIRTEEN
  342.             sayfile( '13.iff' )
  343.         CASE PH_FOURTEEN
  344.             sayfile( '14.iff' )
  345.         CASE PH_FIFTEEN
  346.             sayfile( '15.iff' )
  347.         CASE PH_SIXTEEN
  348.             sayfile( '16.iff' )
  349.         CASE PH_SEVENTEEN
  350.             sayfile( '17.iff' )
  351.         CASE PH_EIGHTEEN
  352.             sayfile( '18.iff' )
  353.         CASE PH_NINETEEN
  354.             sayfile( '19.iff' )
  355.         CASE PH_TWENTY
  356.             sayfile( '20.iff' )
  357.         CASE PH_THIRTY
  358.             sayfile( '30.iff' )
  359.         CASE PH_FORTY
  360.             sayfile( '40.iff' )
  361.         CASE PH_FIFTY
  362.             sayfile( '50.iff' )
  363.         CASE PH_THE_TIME_IS
  364.             sayfile( 'the_time_is.iff' )
  365.         CASE PH_OCLOCK
  366.             sayfile( 'oclock.iff' )
  367.         CASE PH_OH
  368.             sayfile( 'oh.iff' )
  369.         CASE PH_EXACTLY
  370.             sayfile( 'exactly.iff' )
  371.         CASE PH_AND
  372.             sayfile( 'and.iff' )
  373.         CASE PH_SECOND
  374.             sayfile( 'second.iff' )
  375.         CASE PH_SECONDS
  376.             sayfile( 'seconds.iff' )
  377.         DEFAULT
  378.             Throw(ERR_INT,'sayphrase()')
  379.     ENDSELECT
  380. ENDPROC
  381.  
  382. PROC saynumber( n, leadingzero )
  383.     DEF ones, tens
  384.     ones,tens:=Mod(n,10)
  385.     SELECT tens
  386.         CASE 0
  387.             IF ( leadingzero ) THEN sayphrase( PH_OH )
  388.             saydigit( ones )
  389.         CASE 1
  390.             SELECT ones
  391.                 CASE 0
  392.                     sayphrase( PH_TEN )
  393.                 CASE 1
  394.                     sayphrase( PH_ELEVEN )
  395.                 CASE 2
  396.                     sayphrase( PH_TWELVE )
  397.                 CASE 3
  398.                     sayphrase( PH_THIRTEEN )
  399.                 CASE 4
  400.                     sayphrase( PH_FOURTEEN )
  401.                 CASE 5
  402.                     sayphrase( PH_FIFTEEN )
  403.                 CASE 6
  404.                     sayphrase( PH_SIXTEEN )
  405.                 CASE 7
  406.                     sayphrase( PH_SEVENTEEN )
  407.                 CASE 8
  408.                     sayphrase( PH_EIGHTEEN )
  409.                 CASE 9
  410.                     sayphrase( PH_NINETEEN )
  411.                 DEFAULT
  412.                     Raise()
  413.             ENDSELECT
  414.         CASE 2
  415.             sayphrase( PH_TWENTY )
  416.             IF ( ones<>0 ) THEN saydigit( ones )
  417.         CASE 3
  418.             sayphrase( PH_THIRTY )
  419.             IF ( ones<>0 ) THEN saydigit( ones )
  420.         CASE 4
  421.             sayphrase( PH_FORTY )
  422.             IF ( ones<>0 ) THEN saydigit( ones )
  423.         CASE 5
  424.             sayphrase( PH_FIFTY )
  425.             IF ( ones<>0 ) THEN saydigit( ones )
  426.         DEFAULT
  427.             Throw(ERR_INT,'saynumber()')
  428.     ENDSELECT
  429. ENDPROC
  430.  
  431. CHAR '$VER: DaSayClock v0.4 (12.09.95) Jørgen ''Da'' Larsen',0
  432.